package com.itheima.demo.controller;

import cn.hutool.crypto.digest.DigestUtil;
import com.itheima.demo.service.LoginService;
import com.itheima.xo.common.Result;
import com.itheima.xo.pojo.Login;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author :WuJunJie
 * packageName :com.itheima.demo.controller
 * fileName :LoginController
 * creationTime :2022-11-11 15:51
 */
@RestController
@RequestMapping("login")
@Slf4j
public class LoginController {

    @Autowired
    private LoginService loginService;

    @PostMapping("login/{username}/{password}")
    public Result login(@PathVariable String username,@PathVariable String password){
        Login DBInfo = loginService.findByUsername(username);
        String md5PW = DigestUtil.md5Hex(password);
        if(DBInfo.getPassword().equals(md5PW)){
            return Result.success(null);
        }
        return Result.error();
    }
}
